package com.trade.module.database.operation;

import com.trade.module.database.basic.ConstConfig;

/**
 * @Desc: 数据库连接信息工具类
 * @Version: v1.0 2017/12/6 15:17
 * @Author: zfb
 * @JDK Version: 1.8.0_51
 */
public class DBInfoUtil {

    public DBInfoUtil() {
    }

    public static String getDBUrl(ConstConfig.DBType dbType, String dbIP, String dbPort, String dbName) {
        String dbUrlBase = null;
        switch(dbType.value()) {
            case 1:
                dbUrlBase = "jdbc:oracle:thin:@//{host}:{port}/{dbname}";
                break;
            case 2:
                dbUrlBase = "jdbc:dm://{host}:{port}/{dbname}";
                break;
            case 3:
                dbUrlBase = "jdbc:mysql://{host}:{port}/{dbname}?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true";
                break;
            case 4:
                dbUrlBase = "jdbc:sqlserver://{host}:{port};databaseName={dbname}";
                break;
        }
        return dbUrlBase != null?dbUrlBase.replace("{host}", dbIP).replace("{port}", dbPort).replace("{dbname}", dbName):null;
    }

    public static String getDBDriverName(ConstConfig.DBType dbType) {
        switch(dbType.value()) {
            case 1:
                return "oracle.jdbc.driver.OracleDriver";
            case 2:
                return "dm.jdbc.driver.DmDriver";
            case 3:
                return "com.mysql.jdbc.Driver";
            case 4:
                return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
            default:
                return null;
        }
    }
}
